package com.example.gamelogic;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class Team {

	private int teamN;
	private static int id=0;
	private String name;
	private HashSet<Player> player;
	private int average_strong;
	private int goals;
	private int concending_goal;
	private int games_played;
	private int games_win;
	private int games_draw;
	private int games_lose;
	private int points;

	public Team(String n){
		this.name = n;
		this.player = new HashSet<Player>();
		this.average_strong = 0;
		goals = 0;
		concending_goal=0;
		games_played=0;
		games_win=0;
		games_draw=0;
		games_lose=0;
		points=0;
		id++;
		teamN = id;

	}

	public void addPlayer(Player p){
		if(player.size()<=16){
			player.add(p);
			calculate_team_strong();
		}

	}

	public boolean changePlayer(Player p, Player p2){
		if(removePlayer(p)){
			player.add(p2);
			calculate_team_strong();
			return true;
		}else{
			calculate_team_strong();
			return false;
		}
	}

	public boolean removePlayer(Player p){
		if(player.contains(p)){
			player.remove(p);
			calculate_team_strong();
			return true;
		}else{
			calculate_team_strong();
			return false;
		}
	}

	public void calculate_team_strong(){
		int sum =  0;
		for(Player s: player){
			sum = sum + s.getValue();
		}
		this.average_strong = sum/player.size();
	}

	public String getName() {
		return name;
	}

	public HashSet<Player> getPlayer() {
		return player;
	}

	public int getAverage_strong() {
		return average_strong;
	}

	public void setName(String name) {
		this.name = name;
	}


	public int getTeamnumber() {
		return teamN;
	}

	public int getGoals() {
		return goals;
	}

	public int getConcending_goal() {
		return concending_goal;
	}

	public int getGames_played() {
		return games_played;
	}

	public int getGames_win() {
		return games_win;
	}

	public int getGames_draw() {
		return games_draw;
	}

	public int getGames_lose() {
		return games_lose;
	}

	public int getPoints() {
		return points;
	}


	public void addGoals(int goals) {
		this.goals = this.goals + goals;
	}

	public void addConcending_goal(int concending_goal) {
		this.concending_goal = this.concending_goal+concending_goal;
	}

	public void Update(char u, int home, int away){
		switch(u){
		case 'w':
			games_win++;
			games_played++;
			points = points+3;
			break;
		case 'd':
			games_draw++;
			games_played++;
			points++;
		case 'l':
			games_lose++;
			games_played++;
		}
		
		addGoals(home);
		addConcending_goal(away);
	}



}
